<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
         <script src="./src/icreate.core.js"></script>
    	<script src="./src/icreate.dom.js"></script>
    	<script>
    	var arr=[],
    		push=arr.push,
    		concat=arr.concat;

    	Icreate.extend({
    		next: function (node) {
    			var tmp =node;
    			while(tmp =tmp.nextSibling){
    				if(tmp.nodeType ==1){
    					return tmp;
    				}
    			}
    			return null;
    		},
    		nextAll:function(node){
    			var tmp=node,
    				arr=[];
    			while(tmp=tmp.nextSibling){
    				if(tmp.nodeType==1){
    					arr.push(tmp);
    				}
    			}
    				return arr;
    		},
    		prev:function(node){
    			var tmp =node;
    			while(tmp =tmp.previousSibling){
    				if(tmp.nodeType ==1){
    					return tmp;
    				}
    			}
    			return null;
    			},
	    	prevAll:function(node){
	    			var tmp=node,
	    				arr=[];
	    			while(tmp=tmp.previousSibling){
	    				if(tmp.nodeType==1){
	    					arr.push(tmp);
	    				}
	    			}
	    			return arr;
	    		},
			});

    	Icreate.fn.extend({
    		next:function(){
    			  // 将 this 的所有的下一个兄弟元素组成 Itcast 对象返回
    			return this.pushStack(this.map(function( v ){
    				return Icreate.next(v);
    			}));
    		},
    		nextAll:function(){
				// 返回 this 中所有元素的 所有后面的兄弟元素
				var arr=this.map(function(v){
					return Icreate.nextAll(v);
				});
				// 返回结构: [ [], [], ... ]
                // 将其扁平化
                // [ , , , ... ]
				arr=arr.concat.apply([],arr);
 				// 去重
 				arr=Icreate.unique(arr);
 				//pushStack
 				return this.pushStack(arr);


 				// return this.pushStack(Icreate.unique([].concat.apply([],this.map(function(v){
 				// 		return Icreate.nextAll(v);
 				// }))));
    		},
    		prev:function(){
    			return this.pushStack(this.map(function(v){
    				return Icreate.prev(v);
    			}));
    		},
    		prevAll:function(){
    			return this.pushStack(Icreate.unique([].concat.apply([],this.map(function(v){
    				return Icreate.prevAll(v);
    			}))));
    		},
    		 
    		siblings:function(){
    			var prevAll = this.prevAll().toArray();
    			var nextAll = this.nextAll().toArray();

    			return this.pushStack( prevAll.concat(nextAll));
    		}



    	})





    	</script>
    </head>
    <body>
	    <div>1</div>
	    <div>2</div>
	    <div>3</div>
	    <div id="dv">4</div>
	    <div>5</div>
	    <div>6</div>
	    <div>7</div>
    </body>
    <script>
    	
	    I('#dv').prevAll().each(function(){
	    	this.style.background='red';
	    }).end().nextAll().each(function(){
	    	this.style.background ='green';
	    }).end().each(function(){
	    	this.style.background='blue';
	    })
	    
    </script>
</html>